package org.leetcode.easy.leetcode541;

public class Solution
{
    public String reverseStr(String s, int k) {

        char[] chars = s.toCharArray();
        int loopTime = s.length()/(k);
        int lastStr =s.length()%(2*k);

        for (int i = 0; i < loopTime+1; i+=2*k) {
            reverseStr(chars,i,Math.min(i+k,s.length())-1);
        }


        return new String(chars);
    }

    private void reverseStr(char[]s,int start,int end)
    {

        char temp = 'a';
        while (end>start)
        {
            temp=s[end];
            s[end]=s[start];
            s[start]=temp;

            start++;
            end--;
        }
    }


    public static void main(String[] args) {
        String s  = "abcd";

        Solution solution = new Solution();
        String s1 = solution.reverseStr(s, 2);
        System.out.println(s1);
    }
}
